<?php

namespace App\Admin;

use Illuminate\Database\Eloquent\Model;
use DB;
use App\Admin\Auth;
class Role extends Model
{
    public $table='role';
    public $timestamps=false;

    //将分配的权限进行处理
    public function assignAuth($arr,$id){
        //处理数据
    	//获取auth_ids字段的值
    	$post['auth_ids']=implode(',',$arr);
        //获取auth_ac
        $tmp=Auth::where('pid','!=','0')
        ->whereIn('id',$arr)->get();
        //循环拼凑controller和action
    	$ac='';
    	//var_dump($tmp);
    	foreach ($tmp as $key => $value) {
    		$ac .=$value->controller.'@'.$value->action.',';
    		
    	}
    	//出去末尾的逗号
    	$post['auth_ac']=strtolower(rtrim($ac,',@'));
    	//var_dump($post);die;
    	//修改数据
    	return self::where('id',$id)->update($post);
    }
}
